package com.itheima;

public class ArrDemoSwap {
    public static void main(String[] args) {
        int[] arr = {10,20,30,40,50};
//        swap(arr, 0, 4 );
//        for (int i = 0; i < arr.length; i++) {
//            System.out.println(arr[i]);
//        }
        System.out.println("------------------------");
        int[] arr2 = swap2(arr, 0, 4);
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }
    }

    public static void swap(int[] arr, int i, int j) {
        int temp = arr[j];
        arr[j] = arr[i];
        arr[i] = temp;
    }

    public static int[] swap2(int[] arr ,int i, int j) {
        int[] arr2 = new int[arr.length];
        for (int k = 0; k < arr.length; k++)
            arr2[k] = arr[k];
        int temp = arr2[j];
        arr2[j] = arr2[i];
        arr2[i] = temp;
        return arr2;
    }
}
